package com.midian.model.activity;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.midian.common.utils.StringUtil;
import com.midian.model.common.BaseModel;
import com.midian.model.user.User;
import com.midian.service.user.IUserService;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

/**
 * 图书评论
 * 
 */
@Entity
@Table(name = "activity_comment")
public class ActivityComment extends BaseModel {
//	/**评论者id*/
//	private String userId;
//	/**活动id*/
//	private String activityId;
	/**评论内容*/
	private String content;
	/**用户实体对象*/
	@ManyToOne(optional=true,fetch=FetchType.LAZY)
	@JoinColumn(name="userId")
	@NotFound(action=NotFoundAction.IGNORE)
	private User user;
	@ManyToOne(optional=true,fetch=FetchType.LAZY)
	@JoinColumn(name="activityId")
	@NotFound(action=NotFoundAction.IGNORE)
	private Activity activity;
	
	
	public Activity getActivity() {
		return activity;
	}
	public void setActivity(Activity activity) {
		this.activity = activity;
	}
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
//	public String getUserId() {
//		return userId;
//	}
//
//	public void setUserId(String userId) {
//		this.userId = userId;
//	}

//	public String getActivityId() {
//		return activityId;
//	}
//
//	public void setActivityId(String activityId) {
//		this.activityId = activityId;
//	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}
	
	/**
	 * 帐号描述信息
	 * 
	 * @return
	 */
	@Transient
	public String getAccountDesc() {
		String accountDesc = "";
		if (this.user != null) {

			if (IUserService.USER_FROM_NORMAL.equals(user.getUserfrom()) && StringUtils.isNotBlank(user.getAccount())) {
				accountDesc = user.getAccount();
			} else if (IUserService.USER_FROM_QQ.equals(user.getUserfrom())) {
				accountDesc = "QQ用户";
			} else if (IUserService.USER_FROM_WECHAT.equals(user.getUserfrom())) {
				accountDesc = "微信用户";
			}
		}
		return accountDesc;
	}
	
	/**评论详情提示*/
	@Transient 
	public String getActivityCommentTips(){
		String activityCommentTips = "";
		if(StringUtils.isNotBlank(this.content)){
			activityCommentTips = StringUtil.replaceToHtmlQuot(this.content);
		}
		return activityCommentTips;
	}
	
	@Transient
	/**获取活动图片链接*/
	public String getPicLink() {
		String picLink = "<a href=\"javascript:openACPicsTab('" + super.getId() + "');\" style=\"color:blue;\">查看</a>";
		return picLink;
	}
}
